package com.example.demo.service.impl;

import com.example.demo.entity.User;
import com.example.demo.mapper.UserMapper;
import com.example.demo.service.UserService;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author gyc
 * @date 2018/1/16
 */
@Service
public class UserServiceImpl implements UserService {
    @Resource
    private UserMapper userMapper;
    @Override
    public List<User> findOrdersByUser() {
        return userMapper.findOrdersByUser();
    }

    @Override
    @Cacheable(value = "user",key = "#id")
    public User findUserById(Integer id) {
        User user=userMapper.findUserById(id);
        return user;
    }

    @Override
    @Transactional(rollbackFor =Exception.class )
    @CachePut(value = "user",key = "#user.id")
    public User insertUser(User user) {
         userMapper.insertUser(user);
        return user;
    }
}
